package com.zeus.base.smscenter.service.impl;

import com.zeus.base.privilege.utils.ResultModel;
import com.zeus.base.smscenter.mapper.SupplierMapper;
import com.zeus.base.smscenter.mapper.SupplierPropertyMapper;
import com.zeus.base.smscenter.model.SmsSupplier;
import com.zeus.base.smscenter.model.SmsSupplierProperty;
import com.zeus.base.smscenter.service.ISupplierPropertyService;
import com.zeus.base.smscenter.service.ISupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;


/**
 * 供应商属性Service
 */
@Service
@Transactional(readOnly = true)
public class SupplierPropertyServiceImpl implements ISupplierPropertyService {
    @Autowired
    private SupplierPropertyMapper supplierPropertyMapper;

    @Override
    public List<SmsSupplierProperty> find(Map<String, Object> params) {
        return supplierPropertyMapper.find(params);
    }

    @Override
    @Transactional(readOnly = true)
    public List<SmsSupplierProperty> findList(SmsSupplierProperty supplier) {
        List<SmsSupplierProperty> list = supplierPropertyMapper.findList(supplier);
        return list;
    }

    @Override
    @Transactional(readOnly = true)
    public SmsSupplierProperty selectByCode(String code) {

        return supplierPropertyMapper.selectByCode(code);
    }

    @Override
    @Transactional(readOnly = true)
    public SmsSupplierProperty selectByPrimaryKey(Integer id) {

        return supplierPropertyMapper.selectByPrimaryKey(id);
    }

    @Override
    @Transactional(readOnly = true)
    public SmsSupplierProperty selectByPrimaryKey(String id) {
        return supplierPropertyMapper.selectByPrimaryKey(id);
    }

    @Override
    @Transactional(readOnly = true)
    public SmsSupplierProperty get(SmsSupplierProperty entity) {
        return null;
    }

    @Override
    @Transactional(readOnly = false)
    public ResultModel insert(SmsSupplierProperty entity) {
        ResultModel result = exists(entity);
        if (result.isSuccess()) {
            int r = supplierPropertyMapper.insert(entity);
            if (r == 0)
                result = new ResultModel(false, "操作保存失败");
        }
        return result;
    }

    @Override
    @Transactional(readOnly = false)
    public ResultModel insertSelective(SmsSupplierProperty entity) {
        return null;
    }

    @Override
    @Transactional(readOnly = false)
    public ResultModel update(SmsSupplierProperty entity) {
        ResultModel result = exists(entity);
        if (result.isSuccess()) {
            int r = supplierPropertyMapper.updateByPrimaryKey(entity);
            if (r == 0)
                result = new ResultModel(false, "操作保存失败");
        }
        return result;
    }

    @Override
    @Transactional(readOnly = false)
    public ResultModel updateSelective(SmsSupplierProperty entity) {
        return null;
    }

    @Override
    @Transactional(readOnly = false)
    public ResultModel delete(Integer id) {
        int r = supplierPropertyMapper.deleteByPrimaryKey(id);
        if (r == 0)
            return new ResultModel(false, "操作保存失败");
        return new ResultModel(true, "操作保存成功");
    }

    @Override
    @Transactional(readOnly = false)
    public ResultModel delete(SmsSupplierProperty entity) {
        return null;
    }

    @Override
    @Transactional(readOnly = true)
    public ResultModel exists(SmsSupplierProperty entity) {
        List<SmsSupplierProperty> list = null;//tenantMapper.exists(entity);
        if (list == null || list.size() == 0)
            return new ResultModel(true, "操作保存成功");
        for (SmsSupplierProperty t : list) {
//            if (t.getConsumeTypeCode().toLowerCase().equals(entity.smsSettingMapper().toLowerCase())) {
//                return new ResultModel(false, "消费项目编码已经存在");
//            }
            return new ResultModel(false, "消费项目名称已经存在");
        }
        return new ResultModel(true, "操作保存成功");
    }

    @Override
    @Transactional(readOnly = false)
    public ResultModel deleteByCode(SmsSupplierProperty smsSupplierProperty) {
        int r = supplierPropertyMapper.deleteByCode(smsSupplierProperty);
        if (r == 0) {
            return new ResultModel(false, "操作保存失败:删除现有属性信息时失败");
        }
        return new ResultModel(true, "操作保存成功:删除现有属性信息时成功");
    }

    @Override
    @Transactional(readOnly = false)
    public ResultModel deleteByCodeSuppNo(SmsSupplierProperty smsSupplierProperty) {
        int r = supplierPropertyMapper.deleteByCodeSuppNo(smsSupplierProperty);
        if (r == 0) {
            return new ResultModel(false, "操作保存失败:删除现有属性信息时失败");
        }
        return new ResultModel(true, "操作保存成功:删除现有属性信息时成功");
    }

    @Override
    @Transactional(readOnly = false)
    public List<SmsSupplierProperty> selectByCodeSuppNo(SmsSupplierProperty smsSupplierProperty) {
        return supplierPropertyMapper.selectByCodeSuppNo(smsSupplierProperty);
    }

    @Override
    public List<Map> findTenantCodeByDefaultSupplierNoAndLoginName(Map map) {
        return supplierPropertyMapper.findTenantCodeByDefaultSupplierNoAndLoginName(map);
    }

    @Override
    public List<Map> findLoginNameByTenantCode(String tenant) {
        return supplierPropertyMapper.findLoginNameByTenantCode(tenant);
    }
}
